using B.S.XZYData.Api.Read.Application.Command.Team;
using B.S.XZYData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace B.S.XZYData.Api.Read.Controllers
{
    /// <summary>
    /// 班组控制(读)
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TeamController : ControllerBase
    {
        private readonly IMediator mediator;

        public TeamController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 班组查询分页列表
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回查询分页后的数据统一包装分页类</returns>
        [HttpGet]
        public async Task<ApiPageing<TeamDTO>> GetTeamPage([FromQuery] GetTeamPageCommand request)
        {
            var result = await mediator.Send(request);
            return result;
        }

        /// <summary>
        /// 班组成员查询分页列表
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回查询分页后的数据统一包装分页类</returns>
        [HttpGet]
        public async Task<ApiPageing<TeamMemberDTO>> GetTeamMemberPage([FromQuery] GetTeamMemberPageCommand request)
        {
            var result = await mediator.Send(request);
            return result;
        }

        /// <summary>
        /// 获取班组详情
        /// </summary>
        /// <param name="teamId">班组ID</param>
        /// <returns>返回班组详情</returns>
        [HttpGet]
        public async Task<ApiResult<TeamDetailDto>> GetTeamDetail([FromQuery] int teamId)
        {
            var command = new GetTeamDetailCommand
            {
                TeamId = teamId
            };
            var result = await mediator.Send(command);
            return result;
        }
    }
}
